package cn.wolfcode.rbac.web.intercptor;


import cn.wolfcode.rbac.domain.Employee;
import cn.wolfcode.rbac.util.CurrentUtil;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@Component
public class CheckLoginIntercptor  extends HandlerInterceptorAdapter {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
            throws Exception {
        Employee current = CurrentUtil.getCurrent();
        if(current == null){
            response.sendRedirect("/login.html");
            return false;
        }
        return true;
    }
}
